import React,{useState,useEffect} from 'react'
import { useParams } from 'react-router';
import './Add.css';

//添加画作页面
const Udqa = () => {
    const arr = ['画作id: ','题目id: ','题目内容: ','A选项: ','B选项: ','C选项: ','D选项: ','答案：'];
    const [qa,setQa] = useState({});
    const {qId} = useParams();
    console.log(qId)
    useEffect(() => {
        fetch("https://api.52h5.xyz:3001/oneqa?qId="+qId)
        .then(res=>res.json())
        .then(res=>{
            const{pId,qId,qContext,opA,opB,opC,opD,answer} = res.data[0];
            const arr1 = [pId,qId,qContext,opA,opB,opC,opD,answer]
            console.log(res.data[0]);
            arr.map((item,index)=>setQa({...qa,[item]:arr1[index]}))
        })
    }, [])
    return (
        <div className="board">
            <div className="info">
                <h3>修改题目信息</h3>
                <form action = "https://api.52h5.xyz:3001/udqa" method = "post" enctype="multipart/form-data">
                <div className="addList">
                    <ul>
                        {
                            arr.map((item,index)=>{
                                return(
                                    <li>
                                        <span>{item}</span>
                                        <input name={item}  value={qa[item]} onChange={(e)=>setQa({...qa,[item]:e.target.value})}></input>
                                    </li>
                                )
                            })
                        }
                        <li id="content">
                            <input type="submit" value="提交"/>
                        </li>
                    </ul>
                </div>
                </form>
            </div>
        </div>
    )
}
export default Udqa